<template>
<div class="layerRtb layerRtb-threecolumn layerRtb-right">
    <three-title :title="{name:'评价'}" :close="false">
        <span tag="i" class="rig_close fr" @click="$parent.$parent.clickFourShow()"></span>
    </three-title>
    <div class="layerRtb-scroll thinScroll" v-scrollHeight = "137">
        <div class="analyItem">
            <p class="analyItemTit tx-center">评价</p>
            <div class="analyItemCon">
                <div class="pb10">
                    <el-rate v-model="starLength" @change="starChange1()" v-if="evalData === null"></el-rate>
                    <el-rate v-model="evalData.evaluateStar" v-if="evalData !== null" disabled></el-rate>
                </div>
                <div class="clearfix LinkCellBox" v-if="evalData !== null">
                   <span class="LinkCell fl mr10 mb10 LinkCellActive"   v-for="(item, index) of evalData.projectOrderEvaluateLabelEntityList" :key="index">{{item.label}}</span>
                </div>
                <div class="clearfix LinkCellBox" v-if="evalData === null">
                   <span :class="{ 'LinkCell': true, 'fl': true, 'mr10': true, 'mb10': true, 'LinkCellActive' :  item.flag }" v-for="(item, index) of starList" :key="index" @click="startLabelChange(item)">{{item.markTitle}}</span>
                </div>

                <div class="clearfix">
                    <textarea class="col-md-10" rows="3" v-model="evalData.evaluateContent"   readonly v-if="evalData !== null"></textarea>
                    <textarea class="col-md-10" rows="3" v-model="evaValue" placeholder="您对这次的服务还满意吗？您的评价会帮助我们更好的提升哦~" v-if="evalData === null"></textarea>
                </div>
                <div class="clearfix mt10 fl" v-if="evalData === null">
                    <rx-upload
                        class="fl"
                        :data="{id: 11}" :init="{class: 2, mime: 1}"
                        :elStyle="{width:'90px', height: '80px'}"
                        @success="successUpload">
                        <div class="fl uiImgUpload uiImgUpload-gblock mr10">
                            <a href="javascript:">
                                <span type="file" value="" class="file"></span>
                                <em class="bgIcon file-ico"></em>
                            </a>
                        </div>
                    </rx-upload>
                    <rx-viewer v-for="(item, index) of evalImgArray" :key="index" class="mr10 fl">
                        <div class="look_imgHover fl relative" style="width:78px;height:78px;" >
                            <img :src="item">
                            <div class="upload_finish_div">
                                <div class="upload_finish_bg"></div>
                                <div class="upload_finish_linksm">
                                    <div class="dis-il-block">
                                        <a href="javascript:" class="ImgBtn enlarge_viewer enlarge_link" :data-src="item"></a>
                                        <a href="javascript:" class="ImgBtn delect_link" @click="delectImg(index)"></a>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </rx-viewer>

                    <!-- <rx-viewer :images="evalImgArray" class="fl ml10">
                        <div class="clearfix">
                            <div v-for="(item, index) of evalImgArray" :key="index" class="fl mr10">
                                <img :src="item | smallImg(80, 80)" :alt="index">
                            </div>
                        </div>
                    </rx-viewer> -->
                </div>
                <div class="clearfix mt10 fl" v-if="evalData !== null">
                    <rx-viewer :images="evalData.projectOrderPhotoEntities" class="fl ml10">
                        <div class="clearfix">
                            <div v-for="(item, index) of evalData.projectOrderPhotoEntities" :key="index" class="fl mr10">
                                <img :src="item.orderPhoto | smallImg(80, 80)" :alt="index">
                            </div>
                        </div>
                    </rx-viewer>
                </div>
            </div>
        </div>
    </div>
    <div class="layerRtb-footer">
        <div class="analyItem">
            <p class="analyItemTit tx-center">综合</p>
            <div class="analyItemCon">
               <div class="tx-center">
                    <input type="button" class="uiBtn-normal uiBtn-blue" value="确定" @click="submitDate()">
                </div>
            </div>
        </div>
    </div>
</div>
</template>
<script>
import { mapGetters, mapMutations } from 'vuex'
import { GetDistributionEvaluateMarkItems, OperateOrderEvaluateByClient } from '../../../Resources/Api/index'
export default {
    props: [
        'orderid'
    ],
    data () {
        return {
            starLength: 3, // 几个星
            starList: [], // 星星标签
            evalDateList: [], // 星星数据
            evalImgArray: [], // 图片
            evalIdArray: [],
            evaValue: '',
            evalData: null // 评价数据
        }
    },
    computed: {
        ...mapGetters(['leftInfo', 'twoToThreeInfo', 'userInfo'])
    },
    created () {
        this.GetDistributionEvaluateMarkItems() // 获取评价标签内容
    },
    methods: {
        ...mapMutations({
            setUpDatePlate: `SET_UPDATE_PLATE`
        }),
        // 改变星星
        starChange1 () {
            const currentDate = this.evalDateList.filter((item) => { return Number(item.starNum) === this.starLength })
            this.starList = currentDate[0].items
            this.starList.forEach(item => {
                this.$set(item, 'flag', false)
            })
            this.evalIdArray = []
        },
        // 标签点击
        startLabelChange (item) {
            item.flag = !item.flag
            if (item.flag) {
                this.evalIdArray.push(item.markID)
            } else {
                const currentIndex = this.evalIdArray.findIndex((item) => { return item === item.markID })
                this.evalIdArray.splice(currentIndex, 1)
            }
        },
        // 上传图片
        successUpload (value) {
            this.evalImgArray.push(value.src)
        },
        // 删除图片
        delectImg (index) {
            this.evalImgArray.splice(index, 1)
        },
        // 获取评价数据
        GetDistributionEvaluateMarkItems () {
            let parm = {
                eType: 3
            }
            GetDistributionEvaluateMarkItems(parm).then(results => {
                if (results.data.statusCode === 1) {
                    this.evalDateList = results.data.body
                    if (this.evalDateList.length > 0) {
                        const currentDate = this.evalDateList.filter((item) => { return Number(item.starNum) === this.starLength })
                        this.starList = currentDate[0].items
                        this.starList.forEach(item => {
                            this.$set(item, 'flag', false)
                        })
                    }
                }
            }).catch(error => {
                console.log(error)
            })
        },
        // 提交数据
        submitDate () {
            let evaluateInfo = {
                evaluateStar: this.starLength,
                markItems: this.evalIdArray
            }
            let parm = {
                orderId: this.orderid,
                photos: this.evalIdArray.length > 0 ? this.evalIdArray.join(',') : '',
                remark: this.evaValue,
                evaluateInfo: evaluateInfo,
                userName: this.userInfo.as_fullName
            }
            // 接口订单数据
            OperateOrderEvaluateByClient(parm).then(results => {
                if (results.data.statusCode === 1) {
                    this.setUpDatePlate()
                    this.$parent.$parent.clickFourShow()
                }
            }).catch(error => {
                console.log(error)
            })
        }
    }
}
</script>
<style>
    .LinkCell {
        background: #f1f1f1;
        padding:2px 5px;
        border: 1px solid #f1f1f1;
        border-radius: 15px;
        cursor: pointer;
    }
    .LinkCellActive {
        background: #ffeed6;
        color:  #ff9600;
        border-color: #ff9600;
    }
</style>
